package com.misty.admin.controller.adminController;


import com.misty.admin.service.CommentService;
import com.misty.common.bean.Result;
import com.misty.dao.domain.Comment;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author cthulhu
 * @since 2022-11-21
 */
@RestController
@RequestMapping("/comment")
@PreAuthorize("hasAuthority('comment')")
public class CommentController {

    @Autowired
    private CommentService commentService;

    @PostMapping("/save")
    public Result<?> save(@RequestBody Comment comment) {
        return commentService.saveComment(comment);
    }

    @PutMapping("/update")
    public Result<?> update(@RequestBody Comment comment) {
        return commentService.updateComment(comment);
    }

    @DeleteMapping("/delete")
    public Result<?> delete(@RequestParam(name = "id") Integer commentId) {
        return commentService.deleteComment(commentId);
    }

    @GetMapping()
    public Result<?> Page(
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize,
            @RequestParam(defaultValue = "") String search
    ) {
        return commentService.Page(pageNum,pageSize,search);
    }
}

